package com.joven.core.controller;

import com.joven.core.constant.ResultInfo;
import com.joven.core.mapper.UserMapper;
import com.joven.core.model.User;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author joven_wong
 * 2021/7/6 14:49
 */
@Api(tags = "测试案例接口")
@RestController
@RequestMapping("/swagger")
public class Swagger2Controller {

    @Autowired
    UserMapper userMapper;

    @ApiResponses({
            @ApiResponse(code = 2000, message = "操作成功"),
            @ApiResponse(code = 5000, message = "操作异常") })
    @ApiOperation("添加用户的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "姓名"),
            @ApiImplicitParam(name = "addr", value = "联系地址"),
            @ApiImplicitParam(name = "age", value = "年龄")
    })
    @PostMapping("/add")
    public ResultInfo addUser(User user){
        userMapper.insert(User.builder().
                name(user.getName()).addr(user.getAddr())
                .age(user.getAge()).build());
        return ResultInfo.success();
    }

    @ApiOperation(value = "获取根据Id用户信息")
    @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long")
    @GetMapping(value = "/find/{id}")
    public ResultInfo getUserOne(@PathVariable Long id){
        User user = userMapper.selectById(id);
        return ResultInfo.success(user);
    }


}
